<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/js/axios.min.js"></script>
    <script>
        function $(id) {
            return document.getElementById(id)
        }

        function checkCode() {
            axios.get("/newuser/login", {
                params: {
                    userCode: $("userCode").value,
                    name: $("name").value,
                    pwd: $("pwd").value
                }
            }).then(resp => {
                var codeInfo = resp.data;
                if (codeInfo == "nono") {
                    $("infoSpan").style.color = "red";
                    $("infoSpan").innerHTML = "验证码错误";
                } else {
                    $("infoSpan").style.color = "green";
                    $("infoSpan").innerHTML = "正确"
                }
            })
        }

        function changeCode() {
            var imgObj = document.getElementById("codeImg");
            imgObj.src = "/checkCode?" + Math.random();
        }

        function login() {
            if ($("infoSpan").innerHTML = "正确") {
                axios.get("/newuser/login", {
                    params: {
                        userCode: $("userCode").value,
                        name: $("name").value,
                        pwd: $("pwd").value
                    }
                }).then(resp => {
                    var status = resp.data;
                    if (status == "yes") {
                        location.href = "/index.html";
                    } else {
                        $("status").style.color = "red";
                        $("status").innerHTML = "登录失败"
                    }
                })
            }
        }
    </script>
</head>
<body>
<form action="/newuser/login">
    <span id="status"></span><br>
    用户名：<input type="text" id="name" name="name"><br>
    密码：<input type="password" id="pwd" name="pwd"><br>
    <img src="/checkCode" id="codeImg">
    <a href="javascript:changeCode()">看不清楚，换一张</a><br>
    请输入验证码：<input type="text" id="userCode" name="userCode" onblur="checkCode()">
    <span id="infoSpan"></span><br>
    <input type="button" value="登 录" onclick="login()">
</form>

</body>
</html>